#include "./compile_run.hpp"
#include "../commen/httplib.h"

void usage(const std::string& proc)
{
    std::cout << "usage : " << proc << "+" << "port" << std::endl;
}

int main(int argc, char* argv[])
{

    if (argc != 2)
    {
        usage(argv[0]);
        return 1;
    }

    httplib::Server svr;

    // //用来进行基本测试
    // svr.Get("/hello", [](const httplib::Request& request, httplib::Response& response)->void
    // {
    //     response.set_content("hello 世界!", "text/plain;charset=utf-8");
    // });

    svr.Post("/compile_run", [](const httplib::Request& request, httplib::Response& response)->void
    {
        //用户请求的服务正文是我们想要的json string
        std::string in_json = request.body;
        //运行完毕,需要返回去的结果json string
        std::string out_json = "";
        if (!in_json.empty())
        {
            ns_compile_run::compile_run::start(in_json, &out_json);
            response.set_content(out_json, "application/json;charset=utf-8");
        }
    });

    
    svr.listen("0.0.0.0", atoi(argv[1]));

    return 0;
}
